package com;

import java.io.BufferedInputStream;
import java.io.IOException;
import java.util.LinkedList;
import java.util.Queue;


public class Main {
    static Queue<Node> nodes = new LinkedList<>();
    static class Node{
        int data;
        Node left;
        Node right;
        public Node(){}



        public void setData(int data) {
            this.data = data;
        }


        public void setLeft(Node left) {
            this.left = left;
        }

        public void setRight(Node right) {
            this.right = right;
        }
    }
    public static void createNode(Node node,BufferedInputStream bif){
        try {
            int ch ;
            if((ch=bif.read())!=-1) {
                if(ch=='#'){
                    node=null;
                    return;
                }else{
                    node.setData(ch);
                    node.setLeft(new Node());
                    node.setRight(new Node());
                    createNode(node.left,bif);
                    createNode(node.right,bif);
                }
            }else{
                return;
            }
        }catch (IOException e){

        }
    }
    public static void print(Node head){
        if(head==null) {
            return;
        }
        nodes.add(head);
        while(!nodes.isEmpty()){
            Node newNode = nodes.poll();
            if(newNode.data!=0) {
                System.out.print((char) newNode.data);
            }
            if(newNode.left !=null) {
                nodes.add(newNode.left);
                nodes.add(newNode.right);
            }
        }

    }
    public static void main(String[] args){
        BufferedInputStream is = new BufferedInputStream(System.in);
        Node n = new Node();
        createNode(n,is);
        print(n);
    }

}